c###penang.for
      SUBROUTINE PENANG(K)
C--------------------------------
C
C     THIS ROUTINE CALCULATES THE PENETRATION ANGLE FOR EACH LAYER
C
C     LAW OF SINES, SNELL"S LAW AND TABLE INCREMENTS ARE BEING COMBINED
C
      COMMON/REFLX/DELFX(45,3),HPFLX(45,3),HTFLX(45,3),GDFLX(45,3),FVFLX
     A (45,3),DSKPKM(3),DELSKP(3),HPSKP(3),HTSKP(3),DMAXKM(3),FVSKP(3)
     B ,ISKP(3),IMODE(45,3),AFFLX(45,3),DELPEN(3,5),GML(45,3),FHP(45,3)
      COMMON /CON /D2R, DCL, GAMA, PI, PI2, PIO2, R2D, RZ, VOFL
      COMMON /RON /CLAT(5), CLONG(5), GLAT(5), RD(5), FI(3,5), YI(3,5),
     1HI(3,5), HPRIM(30,5), HTRUE(30,5), FVERT(30,5),KM,KFX, AFAC(30,5),
     2HTR(50,3), FNSQ(50,3)
      COMMON/FRQ/FREA(13),FREL(29),FREQ,JMODE,ITXRCP(2)
      FMHZ = FREQ
C.....USE CUSP FOR E LAYER
      HT = HTRUE (10, K)
      FV = FVERT (10, K)
      FRAT = FV / FREQ
      FRAT = FRAT * FRAT
      IF (FRAT - 0.9999)110, 105, 105
  105 DELPEN (1, K) = 89.9
      DELPEN (2, K) = 90.0
      DELPEN (3, K) = 90.0
      GO TO 205
  110 CDEL = (RZ + HT) * SQRT (1. - FRAT) / RZ
      IF (CDEL - .999999)115, 115, 125
  115 DELPEN (1, K) = ACOS (CDEL) * R2D
      GO TO 135
  125 DELPEN (1, K) = 0.0
  135 IF (FI (2, K))145, 145, 180
  145 DELPEN (2, K) = DELPEN (1, K)
  155 CONTINUE
C   REFLECTION UNTIL MAX(RZ+HT)*MU , NOT UNTIL MIDDLE OF LAYER
C.....BUT F LAYER IS SENSITIVE TO SPERICAL SYMMETRY DUE TO THICKNESS
      IF(FVERT(30,K) - FREQ + 0.0001 ) 156,160,160
  156 XM28 = (RZ + HTRUE(28,K)) * SQRT(1.0 - (FVERT(28,K) / FMHZ) ** 2 )
      XM29 = (RZ + HTRUE(29,K)) * SQRT(1.0 - (FVERT(29,K) / FMHZ) ** 2 )
      XM30 = (RZ + HTRUE(30,K)) * SQRT(1.0 - (FVERT(30,K) / FMHZ) ** 2 )
      IF(XM30 - XM29) 161, 157, 157
  157 IF(XM30 - XM28) 158, 159, 159
  158 CDEL = XM28 / RZ
      GO TO 163
  159 CDEL = XM30 / RZ
      GO TO 163
  160 DELPEN(3,K) = 89.9
      GO TO 205
  161 IF(XM29 - XM28) 158, 162, 162
  162 CDEL = XM29 / RZ
  163 CONTINUE
      IF (CDEL - .999999)170, 170, 175
  170 DELPEN (3, K) = ACOS (CDEL) * R2D
      GO TO 205
  175 DELPEN (3, K) = 0.0
      DSKPKM (K) = - 1.
      DMAXKM (K) = - 1.
      RETURN
C.....JUST USE CUSP FOR F1 LAYER
  180 HT = HTRUE (20, K)
      FV = FVERT (20, K)
      FRAT = FV / FREQ
      FRAT = FRAT * FRAT
      IF (FRAT - 0.9999)190, 185, 185
  185 DELPEN(2,K) = 89.9
      DELPEN (3, K) = 90.
      GO TO 205
  190 CDEL = (RZ + HT) * SQRT (1. - FRAT) / RZ
      IF (CDEL - .999999)195, 195, 200
  195 DELPEN (2, K) = ACOS (CDEL) * R2D
      GO TO 155
  200 DELPEN (2, K) = 0.
      GO TO 155
  205 CONTINUE
      RETURN
      END
C--------------------------------
